import 'package:chop/Model/address_entity.dart';
import 'package:chop/common/StringUtils.dart';
import 'package:chop/view/map/New_location.dart';
import 'package:chop/view/sendyou/send_address_page.dart';
import 'package:chop/widgets/TextSizeWidget.dart';
import 'package:chop/widgets/Textwidget.dart';
import 'package:chop/widgets/ToastWidget.dart';
import 'package:chop/widgets/appBar.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class Pickup_job extends StatefulWidget {
  @override
  _Pickup_jobState createState() => _Pickup_jobState();
}

class _Pickup_jobState extends State<Pickup_job> {
  TextEditingController _address; //地址
  TextEditingController _Specific_floor_number; //具体门牌号
  TextEditingController _telephone_number; //发货人电话
  TextEditingController _Specific_name; //发货人姓名
  AdrEntityData data;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _address = TextEditingController();
    _Specific_floor_number = TextEditingController();
    _telephone_number = TextEditingController();
    _Specific_name = TextEditingController();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: BaseViewBar(
          childView: BaseTitleBar("请选择您的取货地址"),
          preferredSize: Size.fromHeight(50.0),
        ),
        body: Stack(
          children: <Widget>[
            ListView(
              children: <Widget>[
                Container(
                  padding: EdgeInsets.fromLTRB(20.0, 30.0, 10.0, 20.0),
                  child: Form(
//          key: _formKey,//绑定状态属性
                    child: Column(
                      children: <Widget>[
                        TextOpenMap(
                          controller: _address,
                          helperText: "请在地图上选取取货地址",
                          labelText: "address",
                          click: () async {
                            data = await Get.to(NewLocation());
                            if(data != null){
                              _address.text = data.address;
                              print("____________<${data.address}");
                            }
                          },
                          btnClick: () async{
                            data = await Get.to(sendAddressPage(isSend: true,));
                            if(data!=null){
                              _address.text = data.address;
                              _Specific_floor_number.text = data.remark;
                              _telephone_number.text = data.phone;
                              _Specific_name.text = data.name;
                            }
                          },
                        ),
                        TextWidget(
                          controller: _Specific_floor_number,
                          labelText: "Specific floor number",
                          helperText: "请填写详细门牌号",
                        ),
                        TextWidget(
                          controller: _telephone_number,
                          labelText: "Specific telephone number",
                          helperText: "请填写您的电话",
                        ),
                        TextWidget(
                          controller: _Specific_name,
                          labelText: "Specific name",
                          helperText: "请填写您的姓名",
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
            Positioned(
              bottom: 0,
              width: MediaQuery.of(context).size.width,
              child: Container(
                child: Row(
                  children: <Widget>[
                    Expanded(
//                      flex: 7,
                      child: RaisedButton(
                        //提交按钮
                        color: Colors.lightBlueAccent,
                        highlightColor: Colors.blueAccent,
                        splashColor: Colors.blue,
                        colorBrightness: Brightness.dark,
//                        shape: RoundedRectangleBorder(
//                          //四角圆角
//                            borderRadius: BorderRadius.circular(10)),
                        onPressed: () {
                          if (StringUtils.isNull(_address.text)) {
                            return Toast.toast(context,
                                msg: "请填写收货地址",
                                position: ToastPostion.bottom);
                          } else if (StringUtils.isNull(
                              _telephone_number.text)) {
                            return Toast.toast(context,
                                msg: "请填写手机号码",
                                position: ToastPostion.bottom);
                          } else if (StringUtils.isNull(
                              _Specific_name.text)) {
                            return Toast.toast(context,
                                msg: "请填写收货人姓名",
                                position: ToastPostion.bottom);
                          } else {
                            data.address = _address.text.trim();
                            data.remark = _Specific_floor_number.text.trim();
                            data.phone = _telephone_number.text.trim();
                            data.name = _Specific_name.text.trim();
                            Get.back(result: data);
//                            Navigator.pop(context, data);
                          }
                        },
                        child: FixedSizeText(
                          '提交地址',
                          style: TextStyle(color: Colors.white, fontSize: 15),
                        ),
                      ),
                    ),

                  ],
                ),

              ),
            ),
          ],
        ));
  }
}
